package com.jsy.mini12306.travel;

import com.aliyun.oss.OSS;
import com.aliyun.oss.model.ListObjectsRequest;
import com.aliyun.oss.model.OSSObjectSummary;
import com.aliyun.oss.model.ObjectListing;
import com.jsy.mini12306.travel.config.OssConfig;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author: SongyangJi
 * @description:
 * @since: 2021/9/5
 */

@SpringBootTest
public class App {

    @Resource
    OssConfig ossConfig;


    @Test
    void test() {

        String protocol = "https://";
        String bucket = ossConfig.getBucket();
        String endPoint = ossConfig.getEndpoint();
        String preFix = "front-vue-static-resources/travel-images";
        OSS ossClient = ossConfig.getOssClient();
        ObjectListing objectListing = ossClient.listObjects(new ListObjectsRequest(bucket).withPrefix(preFix));
        List<OSSObjectSummary> sums = objectListing.getObjectSummaries();
        for (OSSObjectSummary s : sums) {
            String url = protocol + bucket + "." + endPoint + "/" + s.getKey();
            System.out.println(url);
        }


    }
}
